package ch.bfh.mobicomp.soda2.magnetometer;

import java.io.Serializable;

import android.app.Service;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class SharedPreferencesManager implements Serializable{

	private static final long serialVersionUID = 1L;
	private SharedPreferences.Editor editor;
	private SharedPreferences sharedPreferences;
	public static final String KEY_IS_MOVING = "isMoving";

	public SharedPreferencesManager(Service service) {
		this.sharedPreferences =  PreferenceManager.getDefaultSharedPreferences(service);
	}

	public boolean addBoolean(String key, boolean flag) {
		editor = this.sharedPreferences.edit();
		editor.putBoolean(key, flag);
		return editor.commit();
	}

	public boolean findBoolean(String key) {
		return this.sharedPreferences.getBoolean(key, false);
	}
	
	public boolean setIsMoving(boolean isMoving) {
		return this.addBoolean(KEY_IS_MOVING, isMoving);
	}
	
	public boolean getIsMoving() {
		return this.findBoolean(KEY_IS_MOVING);
	}

}
